package com.android.fragmentdemo
import android.graphics.BitmapFactory
import android.os.Bundle
import com.hengfoxwolf.commonbase.base.BaseActivity
import com.android.fragmentdemo.databinding.ActivityQrcodeBinding
import com.android.fragmentdemo.util.BitmapUtil
import com.android.fragmentdemo.util.QRCodeUtil

class QRCodeActivity : BaseActivity<ActivityQrcodeBinding>() {

    override fun getLayoutId() = R.layout.activity_qrcode

    override fun init(savedInstanceState: Bundle?) {

        val url = "https://www.baidu.com/"

        val mBitmap0 = QRCodeUtil.createQRCode(url, 120, 120)
        if (mBitmap0 != null) {
            mBinding.ivQrcode0.setImageBitmap(mBitmap0)
        }

        val qrWidth = resources.getDimension(R.dimen.dp_120).toInt()
        val mBitmap1 = BitmapUtil.createQRCode(url, qrWidth, qrWidth)
        if (mBitmap1 != null) {
            mBinding.ivQrcode1.setImageBitmap(mBitmap1)
        }

        val qrWidth2 = resources.getDimension(R.dimen.dp_120).toInt()
        val bmpIcon = BitmapFactory.decodeResource(resources, R.drawable.ic_fail)

        val mBitmap2 = BitmapUtil.createQRCodeWithLogo(url, qrWidth2, qrWidth2, bmpIcon)
        if (mBitmap2 != null) {
            mBinding.ivQrcode2.setImageBitmap(mBitmap2)
        }

        val mBitmap3 = BitmapUtil.createQRCodeWithLogo(url, qrWidth2, bmpIcon)
        if (mBitmap3 != null) {
            mBinding.ivQrcode3.setImageBitmap(mBitmap3)
        }
    }
}